//
//  MMMomentsViewModel.swift
//  MoMo
//
//  Created by 高得华 on 2020/7/23.
//  Copyright © 2020 华&梅. All rights reserved.
//

import UIKit

// - ==== 动态、朋友圈、时刻
class MMMomentsViewModel: MDHSegmentedControlViewModel {
    ///顶部的点击事件 1:排行榜 2:搜索
    let subTNavClick = RACSubject<AnyObject>()
    ///选中的cat
    var category = MMV1ChatChatlistCategoryModel()
    ///categorys
    @objc dynamic var categorys = [MMV1ChatChatlistCategoryModel]()
    ///key值 用户判断是否需要进行更新 分类
    @objc dynamic var keyCategory = ""
    ///adimages
    @objc dynamic var adimages = [MMBannerListModel]()
    ///key值 用户判断是否需要进行更新 广告
    @objc dynamic var keyAdimages = ""
    ///ad_url
    @objc dynamic var ad_urls = [String]()
    ///ad_titles
    @objc dynamic var ad_titles = [String]()
    
    override init(services: MDHViewModelServices, params: [AnyHashable : Any]) {
        super.init(services: services, params: params)
        let style1 = params[MHViewModelIDKey] as? Int ?? 0
        self.viewStyle = style1
    }
    
    override func initialize() {
        super.initialize()
        
        self.title = "动态"
        self.navigationBackgroundAlpha = 0.001
        //self.shouldPullDownToRefresh = true
        self.prefersNavigationBarHidden = true
        self.isNeedIndicatorPositionChangeItem = true
        self.preferredCategoryViewHeight = ceil(40*kMDHPTAutoScale())

        //首页
        let names = ["全部", "关注"]
        for (i, name) in names.enumerated() {
            let model = MMV1ChatChatlistCategoryModel()
            model.name = name
            model.cid = "\(i-1)"
            self.categorys.append(model)
            if i == 0 {
                self.category = model
            }
        }
        self.titles = names
        
        ///点击事件
        self.subTNavClick
            .deliverOnMainThread().subscribeNext { [weak self] (x) in
                if let weakSelf = self {
                    let vs = x as? Int ?? 0
                    switch vs {
                    case 1:///我的房间
                        //let images = ["https://huohufm.oss-cn-qingdao.aliyuncs.com/connect/weixin.jpg"]
                        //kMDHPhotoBM().showPhoto(images, index: 0)
                        MDHSwiftHeader.pushChatroomVc(roomId: "-1")
                        break
                    case 2:///搜索
                        let vm = MMSearchTableViewModel.init(services: weakSelf.services, params: [AnyHashable : Any]())
                        let vc = MDHRouter.sharedInstance().viewController(for: vm)
                        let an_type = "rippleEffect"//CATransitionType(rawValue: "rippleEffect")
                        let animator = TLCATransitonAnimator.init(transitionType: an_type, direction: TLDirectionToBottom, transitionTypeOfDismiss: an_type, directionOfDismiss: TLDirectionToBottom);
                        animator.transitionDuration = 0.25
                        AppDelegate.topViewController().push(vc, animator: animator)
                        //weakSelf.services.present(vm, animated: true) { }//push(vm, animated: true)
                        break
                    case 3:///更多
                        
                        break
                    default:
                        break
                    }
                }
        }
    }
}
